package com.coderman.infosys.auth.adapter.controller.config;

import com.coderman.infosys.auth.adapter.controller.BaseController;
import com.coderman.infosys.auth.adapter.convert.DataColumnConverter;
import com.coderman.infosys.auth.domain.bo.config.DataColumnBO;
import com.coderman.infosys.auth.domain.gataway.DataColumnConfigGataway;
import com.coderman.infosys.plat.auth.common.dto.ResultDataDto;
import com.coderman.infosys.plat.auth.common.page.PageBO;
import com.coderman.infosys.plat.auth.common.vo.PageVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import com.coderman.infosys.auth.adapter.vo.config.DataColumnVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


/**
* @Description:控制层
* @Author:
* @CreateTime:2022-01-04 15:27:39
* @version v1.0
*/
@RestController
public class DataColumnController extends BaseController {
	
	protected Logger logger = LoggerFactory.getLogger(DataColumnController.class);


	@Autowired
	private DataColumnConfigGataway dataColumnConfigGataway;

	/**
	 *
	 * @Description 获取数据字段信息
	 * @param busDataBase
	 * @return List<DataColumnVO>
	 */
	@RequestMapping(value = "/datacolumn/getbycode")
	public ResultDataDto<List<DataColumnVO>> getListByBusDataBase(@RequestParam(value = "busDataBase", required = true) String busDataBase){
		List<DataColumnBO> dataColumnBOList = dataColumnConfigGataway.getByBusDatabase(busDataBase);
		return ResultDataDto.success(DataColumnConverter.INSTANCE.BOs2VOs(dataColumnBOList));
	}

	/**
	 *
	 * @Description 分页获取数据字段信息
	 * @param pageVO
	 * @return PageVO<DataColumnVO>
	 */
	@RequestMapping(value = "/datacolumn/pagelist")
	public ResultDataDto<PageVO> getPageList(@RequestParam(value = "pageVO", required = true) PageVO pageVO){
		PageBO pageBO = pageVO.convertToBO();
		List<DataColumnBO> dataColumnBOList = dataColumnConfigGataway.getPageList(pageBO);
		return ResultDataDto.success(pageVO.initData(DataColumnConverter.INSTANCE.BOs2VOs(dataColumnBOList),pageBO.getTotalRows()));
	}

	/**
	 *
	 * @Description 导入数据字段列表
	 * @param dataColumnVOList
	 * @return Boolean
	 */
	@RequestMapping(value = "/datacolumn/import")
	public ResultDataDto<Boolean> importDataColumnList(@RequestBody List<DataColumnVO> dataColumnVOList){
		dataColumnConfigGataway.saveBatchDataColumn(DataColumnConverter.INSTANCE.VOs2BOs(dataColumnVOList));
		return ResultDataDto.success(true);
	}
}
